package org.xhy.sniffer.trace;


// 用于链路上下文中创建 span
public class ContextManager {

    private static ThreadLocal<TraceContext> contexts = new ThreadLocal<>();


    public static void startEntry(String operName,CommentDefine comment){
        startEntry(operName,comment,"");
    }

    public static void startEntry(String operName,CommentDefine comment,String peer){
        TraceContext traceContext = contexts.get();
        if (traceContext == null){
            traceContext = new TraceContext();
            contexts.set(traceContext);
        }
        traceContext.createEntrySpan(operName,comment,peer);
    }


    public static void exitEntry(){
        TraceContext traceContext = contexts.get();
        traceContext.createExitSpan();
    }


    public static AbstractSpan activeSpan(){
        TraceContext traceContext = contexts.get();
        return traceContext.getPeekSpan();
    }
}
